﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;
using SqlServerWrapper;
using ResponseObject;
using BartonExtension;
using Model.User;
using Model;
using Google.Maps.Geocoding;


namespace WebSrvs.NET
{
    /// <summary>
    /// ZK_Navigation 的摘要说明
    /// </summary>
    [System.Web.Script.Services.ScriptService]
    [WebService(Namespace = "http://zker.hk/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class ZK_Navigation : System.Web.Services.WebService
    {
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string navigationNodeGenerate(float budget,string catalogs,string brands,int prefer_nav_type)
        {
            //Get NearBy Shop Location
            ZKResponse response = new ZKResponse();
            string connStr = SqlConnectionManager.GetConnStrFromConfig();
            using (SqlConnection conn = SqlConnectionManager.CreateSqlConnection(connStr))
            {
                conn.Open();
                using (SqlCommand cmd = SqlCommandManager.Create(conn, CommandType.StoredProcedure))
                {
                    cmd.CommandText = "proc_get_navigation_path_nodes";
                    cmd.Parameters.Add("@budget", SqlDbType.Float).Value = budget;
                    cmd.Parameters.Add("@prefer_catalogs", SqlDbType.NVarChar).Value = catalogs;
                    cmd.Parameters.Add("@prefer_brands", SqlDbType.NVarChar).Value = brands;
                    cmd.Parameters.Add("@prefer_nav_type", SqlDbType.NVarChar).Value = prefer_nav_type;
                    cmd.Parameters.Add("@return", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
                    try
                    {
                        using (SqlDataReader dr = cmd.ExecuteReader())
                        {
                            DataTable dt = new DataTable("nodes");
                            dt.Load(dr);
                            if (dt.Rows.Count == 0)
                            {
                                response.isProcessSuccess = false;
                                response.errCode = ErrorCodes.CODE_ERR_ON_NAV_NO_NODES_DETECT;
                                response.errMsg = ErrorMsgs.MSG_ERR_ON_NAV_NO_NODES_DETECT;
                            }
                            else
                            {
                                
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        response.errCode = ErrorCodes.CODE_ERR_INTERNAL_ERR;
                        response.errMsg = ex.Message;
                    }
                }
            }
            return response.ToJson();
        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string requestDetailLocationFromAddr(string addr)
        {
            return addr.requestGeometryDataFromAddr().ToJson();
        }

    }
}
